#import "BWQueenStitch.h"

@implementation BWQueenStitch


+ (BWQueenStitch *) newStitchAtX: (int) newX
                               y: (int) newY
                          color1: (NSColor *) newColor1
                          color2: (NSColor *) newColor2
                       direction: (BWQueenStitch_Direction) newDirection
{
    BWQueenStitch *stitch = [[self alloc] init];

    stitch->x = newX;
    stitch->y = newY;
    stitch->color1 = [newColor1 retain];
    stitch->color2 = [newColor2 retain];
    stitch->direction = newDirection;

    return ([stitch autorelease]);

} // newStitchAtX


- (void) dealloc
{
    [color1 release];
    [color2 release];

    [super dealloc];

} // dealloc


- (NSString *) description
{
    NSString *string;

    string = [NSString stringWithFormat: @"BWQueenStitch: (%d, %d), %@",
                       x, y, (direction) ? @"NorthSouth" : @"EastWest"];
    return (string);

} // description



- (int) x
{
    return (x);
} // x


- (int) y
{
    return (y);
} // y


- (NSColor *) color1
{
    return (color1);
} // color1


- (NSColor *) color2
{
    return (color2);
} // color2


- (BWQueenStitch_Direction) direction
{
    return (direction);
} // direction


- (void) setColor1: (NSColor *) color
{
    [color retain];
    [color1 release];

    color1 = color;

} // setColor1

- (void) setColor2: (NSColor *) color
{
    [color retain];
    [color2 release];

    color2 = color;

} // setColor2


- (void) setDirection: (BWQueenStitch_Direction) d
{
    direction = d;

} // setDirection


- (void) setX: (int) newX
{
    x = newX;
} // setX


- (void) setY: (int) newY
{
    y = newY;
} // setY

- (void) encodeWithCoder: (NSCoder *) coder
{
    [coder encodeInt: x  forKey: @"x"];
    [coder encodeInt: y  forKey: @"y"];
    [coder encodeObject: color1  forKey: @"color1"];
    [coder encodeObject: color2  forKey: @"color2"];
    [coder encodeInt: direction  forKey: @"direction"];

} // encodeWithCoder


- (id) initWithCoder: (NSCoder *) coder
{
    if (self = [super init]) {
        x = [coder decodeIntForKey: @"x"];
        y = [coder decodeIntForKey: @"y"];
        color1 = [coder decodeObjectForKey: @"color1"];
        color2 = [coder decodeObjectForKey: @"color2"];
        direction = [coder decodeIntForKey: @"direction"];
    }

    return (self);

} // initWithCoder

@end // BWQueenStitch

